#include "mbox.h"

#include <QPainter>

MBox::MBox(QGraphicsItem *parent) :
    QGraphicsWidget(parent)
{
    visible = true;
    selected = false;
    hint = false;
    active = true;
}

MCard MBox::getCard()
{
    return *card;
}

void MBox::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
{
    if (!visible)
        return;
    QTextOption to;
    to.setAlignment(Qt::AlignCenter | Qt::AlignHCenter);

    QPen q;
    q.setWidth(2);
    if (selected)
    {
        q.setWidth(6);
        QFont f;
        f.setBold(true);
        p->setFont(f);
    }
    if (hint)
    {
        q.setColor(QColor(0, 0, 200));
    }
    if (!active)
    {
        q.setWidth(1);
        q.setColor(QColor(160, 160, 160));
    }

    p->setPen(q);
    p->drawRect(0, 0, SIZE, SIZE);
    p->drawText(QRect(0, 0, SIZE, SIZE), card->str(), to);
}

void MBox::setColorVisible(bool v)
{
    visible = v;
    update();
}

void MBox::setColorActive(bool v)
{
    active = v;
    update();
}

void MBox::setColorHint(bool v)
{
    hint = v;
    update();
}

void MBox::setColorSelected(bool v)
{
    selected = v;
    update();
}
